package com.ihr360.authority.sharing.validator;

import com.ihr360.commons.context.session.Ihr360Session;
import com.ihr360.commons.context.session.Ihr360SessionContextHolder;
import com.ihr360.commons.entity.AuthUserInfo;
import com.ihr360.validation.ValidationUtils;
import com.ihr360.validation.Validator;

public class SessionUserInfoValidator implements Validator<Object> {
    @Override
    public boolean supports(Class<?> clazz) {
        return true;
    }

    @Override
    public void validate(Object target) {

        Ihr360Session session = Ihr360SessionContextHolder.getSession();
        ValidationUtils.rejectIfEmpty(session, null, "无法获取有效会话信息");

        AuthUserInfo userInfo = session.getUserInfo();
        ValidationUtils.rejectIfEmpty(userInfo, null, "无法获取用户会话信息");
        String companyId = userInfo.getCompanyId();
        ValidationUtils.rejectIfEmpty(companyId, null, "无法获取用户公司标识");
        String userId = userInfo.getUserId();
        ValidationUtils.rejectIfEmpty(userId, null, "无法获取用户标识");
    }
}